how do javascript for loops work